package top.starmc.starpet.util

import org.bukkit.inventory.ItemStack
import taboolib.module.nms.ItemTagData
import taboolib.module.nms.getItemTag
import taboolib.platform.util.isNotAir
import taboolib.platform.util.modifyLore
import top.starmc.starpet.config.Config
import top.starmc.starpet.internal.PetData

fun ItemStack.updatePetData(internal: PetData, experience: Int, level: Int): ItemStack {
    modifyLore {
        clear()
        addAll(internal.itemLore.toMutableList().calculate("<:", ":>", experience, internal.getMaxExp(level), level))
    }
    val tag = getItemTag()
    tag["经验"] = ItemTagData(experience)
    tag["等级"] = ItemTagData(level)
    tag.saveTo(this)
    return this
}

fun ItemStack.isPetItem(): Boolean {
    if (isNotAir()) {
        val itemTag = getItemTag()
        return itemTag.containsKey("宠物") && itemTag["宠物"]!!.asString() in Config.internalMap
    }
    return false
}